#include "flip_internal.h"

int luaflip_create_window(lua_State* L)
{
	luaflip_data* data = global_data(L);
	unsigned width = luaL_checkint(L, 1);
	unsigned height = luaL_checkint(L, 2);
	
	if(data->current_window == NULL)
		data->current_window = flip_create_window();
	flip_window_set_mode(data->current_window, width, height, 0);
	flip_window_set_visible(data->current_window, 1);
	return 0;
}

int luaflip_window_update(lua_State* L)
{
	luaflip_data* data = global_data(L);
	int ret = flip_window_update(data->current_window);
	lua_pushinteger(L, ret);
	return 1;
}

int luaflip_window_end_drawing(lua_State* L)
{
	luaflip_data* data = global_data(L);
	flip_draw_flush(&data->draw_buffer);
	flip_window_end_drawing(data->current_window);
	return 0;
}

int luaflip_throttle_fps(lua_State* L)
{
	luaflip_data* data = global_data(L);
	int fps = luaL_checkint(L, 1);
	flip_window_throttle_fps(data->current_window, fps);
	return 0;
}